<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>用户注册-潮聚</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" th:href="@{css/mui.min.css}"/>
		<link rel="stylesheet" th:href="@{css/common.css}"/>
		<link rel="stylesheet" th:href="@{css/icons-extra.css}"/>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">注册</h1>
		</header>

		<div class="cj-line-20"></div>
		<div class="mui-content">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<input  name="Email" type="email" class="mui-input-clear mui-input" placeholder="输入您的邮箱">
				</div>
				<div class="mui-input-row">
					<input  name="Password" type="password" class="mui-input-clear mui-input" placeholder="输入您的密码">
				</div>
				<div class="mui-input-row">
					<input  name="rePassword" type="password" class="mui-input-clear mui-input" placeholder="确认密码">
				</div>
				<div class="mui-input-row">
					<input name="Name" type="text" class="mui-input-clear mui-input" placeholder="输入您的姓名">
				</div>
				<div class="mui-input-row">
					<input name="Phones"  type="text" class="mui-input-clear mui-input" placeholder="输入您的手机号">
				</div>
				<input name="state" value="success" type="hidden" class="mui-input-clear mui-input" placeholder="">
			</form>
			<div class="cj-line-10"></div>
			<div class="mui-content-padded">
				<button id='reg' data-loading-text="注册中" class="mui-btn mui-btn-block mui-btn-primary cj-btn">注册</button>
			</div>
			
		</div>
		<div th:include="common/footer :: nav"></div>
		<script src="js/mui.min.js"></script>
		<script src="js/jquery.min.js"></script>
		<script src="js/common.js"></script>
		<script>
			
			$("#reg").click(function(){
				//检查邮箱
				var email = $("input[name='Email']").val();
				var emailRegx = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
				if(!emailRegx.test(email)){
					mui.toast("请输入正确的邮箱");
					return;
				}else{
					var res;
					$.ajax({
						'url':'/user/emailno?Email='+email,
						'dataType':'json',
						'async':false,
						'success':function(response){
							res = response;
						}
					});
					if(res.code===500){
						mui.toast(res.msg);
						return;
					}
				}
				//检查密码
				var password = $("input[name='Password']").val();
				if(password==null||password==""){
					mui.toast("请输入密码");
					return;
				}
				
				if(password.length<6){
					mui.toast("密码长度不能小于6位");
					return;
				}
				
				var rePassword = $("input[name='rePassword']").val();
				if(password!=rePassword){
					mui.toast("两次密码不一致");
					return;
				}
				
				var name= $("input[name='Name']").val();
				if(name==null||name==""){
					mui.toast("请输入姓名");
					return;
				}
				
				var phoneRegx = /^1\d{10}$/;
				var phone= $("input[name='Phones']").val();
				if(!phoneRegx.test(phone)){
					mui.toast("请输入正确的手机号");
					return;
				}
				
				//注册
				$.ajax({
					url:"/user/register",
					data:$("form").serialize(),
					type:'get',
					dataType:'json',
					beforeSend:function(){
						mui("#reg").button('loading');
					},
					success:function(response){
						//console.log(response);
						if(response.code==200){
							mui.alert('恭喜您注册成功，你需要激活账号才能登陆，请到邮箱激活你的账号！', '注册成功', function() {
								location.href = "/login";
							});
						}
						mui("#reg").button('reset');
					}
				});
			});
		</script>
	</body>
</html>